Skip to content

Conversation

@Grufoony
Copy link
Collaborator

@Grufoony Grufoony commented Feb 6, 2026

TODO:

  • Save edges and nodes data in the db + find a way to identify networks.
  • Rewrite webapp to extract data from the db

dynamics.setSpeedFluctuationSTD(0.1);

// Connect database for saving data
dynamics.connectDataBase(OUT_FOLDER + "simulation_data.db");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 18.4 rule Note

MISRA 18.4 rule
dynamics.setDataUpdatePeriod(30); // Store data every 30 time steps

// Connect database for saving data
dynamics.connectDataBase(OUT_FOLDER + "simulation_data.db");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 18.4 rule Note

MISRA 18.4 rule
#ifdef __APPLE__
std::time_t const t = std::chrono::system_clock::to_time_t(now);
std::ostringstream oss;
oss << std::put_time(std::localtime(&t), "%Y%m%d%H%M%S");

Check notice

Code scanning / Cppcheck (reported by Codacy)

localtime is Y2038-unsafe Note

localtime is Y2038-unsafe
std::filesystem::remove(testFile);
SQLite::Statement cols(db,
"SELECT street_id, density, avg_speed FROM road_data");
while (cols.executeStep()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note test

MISRA 14.4 rule
std::ifstream file(entry.path());
REQUIRE(file.is_open());
// Evolve until agent reaches destination (with limit)
for (int iter = 0; iter < 1000 && dynamics.nAgents() > 0; ++iter) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note test

MISRA 12.1 rule
break;
}
SQLite::Statement cols(db, "SELECT distance_m, travel_time_s FROM travel_data");
while (cols.executeStep()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note test

MISRA 14.4 rule
SQLite::Statement cols(db, "SELECT distance_m, travel_time_s FROM travel_data");
while (cols.executeStep()) {
auto distance = cols.getColumn(0).getDouble();
auto time = cols.getColumn(1).getDouble();

Check notice

Code scanning / Cppcheck (reported by Codacy)

time is Y2038-unsafe Note test

time is Y2038-unsafe
auto distance = cols.getColumn(0).getDouble();
auto time = cols.getColumn(1).getDouble();
CHECK(distance > 0.0);
CHECK(time > 0.0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

time is Y2038-unsafe Note test

time is Y2038-unsafe

file.close();
std::filesystem::remove(testFile);
for (int iter = 0; iter < 1000 && dynamics.nAgents() > 0; ++iter) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note test

MISRA 12.1 rule
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 89.32039% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.42%. Comparing base (9611d9e) to head (c48f2a9).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
src/dsf/mobility/FirstOrderDynamics.cpp 72.09% 12 Missing ⚠️
src/dsf/mobility/RoadDynamics.hpp 93.67% 11 Missing ⚠️
test/mobility/Test_dynamics.cpp 87.17% 0 Missing and 10 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #403      +/-   ##
==========================================
+ Coverage   85.81%   87.42%   +1.61%     
==========================================
  Files          54       53       -1     
  Lines        6190     5941     -249     
  Branches      671      658      -13     
==========================================
- Hits         5312     5194     -118     
+ Misses        862      728     -134     
- Partials       16       19       +3     
Flag Coverage Δ
unittests 87.42% <89.32%> (+1.61%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

/// @brief Copy assignment operator for PointsCluster.
/// @param other The PointsCluster to copy from.
/// @return Reference to this PointsCluster.
PointsCluster& operator=(PointsCluster const& other) = default;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 16.3 rule Note

MISRA 16.3 rule
cluster_radius_km,
max_speed_kph,
min_duration_min](auto& pair) {
max_speed_kph](auto& pair) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 13.1 rule Note

MISRA 13.1 rule
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cppcheck (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@Grufoony Grufoony force-pushed the db branch 2 times, most recently from 5157ae1 to 808fcc9 Compare February 6, 2026 15:54
}

/* Database modal styles */
.modal {

Check warning

Code scanning / Csslint (reported by Codacy)

Rule doesn't have all its properties in alphabetical order. Warning

Rule doesn't have all its properties in alphabetical order.
display: none;
}

.modal-content {

Check warning

Code scanning / Csslint (reported by Codacy)

Rule doesn't have all its properties in alphabetical order. Warning

Rule doesn't have all its properties in alphabetical order.
text-align: center;
}

.modal-content h2 {

Check warning

Code scanning / Csslint (reported by Codacy)

Rule doesn't have all its properties in alphabetical order. Warning

Rule doesn't have all its properties in alphabetical order.
margin-bottom: 20px;
}

.db-input-group input[type="file"] {

Check warning

Code scanning / Csslint (reported by Codacy)

Rule doesn't have all its properties in alphabetical order. Warning

Rule doesn't have all its properties in alphabetical order.
border-color: #4CAF50;
}

.db-status {

Check warning

Code scanning / Csslint (reported by Codacy)

Rule doesn't have all its properties in alphabetical order. Warning

Rule doesn't have all its properties in alphabetical order.
text-align: center;
}

.modal-content h2 {

Check notice

Code scanning / Csslint (reported by Codacy)

Heading (h2) should not be qualified. Note

Heading (h2) should not be qualified.
border: 2px dashed #ccc;
border-radius: 5px;
width: 100%;
box-sizing: border-box;

Check notice

Code scanning / Csslint (reported by Codacy)

The box-sizing property isn't supported in IE6 and IE7. Note

The box-sizing property isn't supported in IE6 and IE7.
min-height: 20px;
}

.db-status.error {

Check notice

Code scanning / Csslint (reported by Codacy)

Adjoining classes: .db-status.error Note

Adjoining classes: .db-status.error
color: #c62828;
}

.db-status.success {

Check notice

Code scanning / Csslint (reported by Codacy)

Adjoining classes: .db-status.success Note

Adjoining classes: .db-status.success
color: #2e7d32;
}

.db-status.loading {

Check notice

Code scanning / Csslint (reported by Codacy)

Adjoining classes: .db-status.loading Note

Adjoining classes: .db-status.loading
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylelint (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.


// Grufoony - 9/2/2026
// TODO: make this dynamic based on data range
const MAX_DENSITY = 200;

Check notice

Code scanning / Jshint (reported by Codacy)

Prohibits the use of __iterator__ property due to compatibility issues Note

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
// Grufoony - 9/2/2026
// TODO: make this dynamic based on data range
const MAX_DENSITY = 200;
const MAX_DENSITY_INVERTED = 1 / MAX_DENSITY;

Check notice

Code scanning / Jshint (reported by Codacy)

Prohibits the use of __iterator__ property due to compatibility issues Note

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates simulation output from CSV files to a SQLite database, updates the C++ simulation engine to write structured results into that DB, and rewrites the webapp to load and visualize simulations directly from the SQLite file (including selecting which simulation run to view).

Changes:

  • Add SQLite-backed persistence for per-street data, aggregate stats, travel data, simulation metadata, and network topology (edges/nodes).
  • Update the webapp UI/JS to load a user-selected SQLite database in-browser (sql.js) and select a simulation to visualize.
  • Remove the legacy AdjacencyMatrix API, tests, and Python bindings that depended on it; refresh examples/tests to use DB saving.

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
webapp/index.html Adds sql.js dependency and a modal to select/load a SQLite DB.
webapp/styles.css Styles for the new DB-load modal.
webapp/script.js Switches data loading from CSV/config to SQLite queries + simulation selection flow.
src/dsf/base/Dynamics.hpp Adds simulation id and SQLite DB connection handling.
src/dsf/mobility/RoadDynamics.hpp Adds DB schema initialization, network dump, and DB-backed saving in evolve().
src/dsf/mobility/FirstOrderDynamics.hpp / .cpp Implements dumping simulation parameters into a simulations table.
src/dsf/mobility/RoadNetwork.hpp / .cpp Removes AdjacencyMatrix-based construction and related includes/ctors.
src/dsf/base/Network.hpp Removes AdjacencyMatrix-based constructor.
src/dsf/bindings.cpp Drops AdjacencyMatrix bindings and replaces CSV save APIs with saveData() + DB connect exposure.
CMakeLists.txt Fetches/links SQLiteCpp and exposes it via dsf target.
examples/slow_charge_tl.cpp / slow_charge_rb.cpp Switch examples from CSV saving to DB saving via connectDataBase() + saveData().
test/mobility/Test_dynamics.cpp Replaces CSV-based save tests with DB table/schema assertions using SQLiteCpp.
test/mobility/Test_graph.cpp Removes AdjacencyMatrix constructor subcase usage.
test/base/Test_AdjacencyMatrix.cpp Deletes AdjacencyMatrix test suite.
src/dsf/base/AdjacencyMatrix.hpp / .cpp Deletes AdjacencyMatrix implementation.
src/dsf/dsf.hpp Removes AdjacencyMatrix include.
src/dsf/mdt/TrajectoryCollection.cpp Fixes lambda capture list (removes unused capture).
src/dsf/mdt/PointsCluster.hpp Adds copy assignment operator.
.gitignore Ignores *.ipynb.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

webapp/script.js Outdated
for (const ts of timestamps) {
// Get all road_data for this timestamp and simulation
const dataResult = db.exec(
`SELECT street_id, density FROM road_data WHERE simulation_id = ${selectedSimulationId} AND datetime = '${ts}'`
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

road_data is created by the simulator with a density_vpk column (see C++ schema), but this query selects density. This will return NULL/throw and the map will show no densities. Update the query (and downstream usage) to read density_vpk (and optionally also pull avg_speed_kph, counts, etc. if needed).

Suggested change
`SELECT street_id, density FROM road_data WHERE simulation_id = ${selectedSimulationId} AND datetime = '${ts}'`
`SELECT street_id, density_vpk FROM road_data WHERE simulation_id = ${selectedSimulationId} AND datetime = '${ts}'`

Copilot uses AI. Check for mistakes.
@Grufoony Grufoony merged commit 45e99fb into main Feb 9, 2026
44 checks passed
@Grufoony Grufoony deleted the db branch February 9, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add possibility to connect to a sql db

1 participant